<script>
import {uploadIdCardSppSecret, uploadUrl, txAppId, uploadIdCardAppId} from './utils/config'
import {getWxConfig} from "@/utils/api/basics";

export default {
  globalData: {
    imgUrl: '',
    token: '',
    appId: '',
    appSecret: '',
    name: '',
    logoUrl: null
    // locationInfo: null
  },
  methods: {
    async getwxuserappconfig() {
      getWxConfig().then(res => {
        console.log(res)
        if (res.data.data.code == 200) {
          this.globalData.name = res.data.data.wxAppName
          this.globalData.logoUrl = res.data.data.wxAppLogo
          console.log('小程序 logo 地址:', this.globalData.logoUrl);
          console.log('小程序 name:', this.globalData.name);
        }
      })
      // let data = await getwxuserappconfiglist()
      // this.globalData.appId=data.data.rows[0].appId
      // this.globalData.appSecret=data.data.rows[0].appSecret
    },
    // 提示弹窗
    alert(content, confirmfun) {
      uni.showModal({
        title: '提示信息',
        showCancel: false,
        content: content.toString(),
        success: function (res) {
          if (res.confirm) {
            typeof confirmfun == 'function' && confirmfun();
          }
        }
      });
    },
    confirm: function (content, confirmfun, cancelfun) {
      uni.showModal({
        title: '操作确认',
        content: content.toString(),
        showCancel: true,
        success: function (res) {
          if (res.confirm) {
            typeof confirmfun == 'function' && confirmfun();
          } else {
            typeof cancelfun == 'function' && cancelfun();
          }
        }
      });
    },
    toastnone: function (title) {

      uni.showToast({
        title: title,
        icon: 'none',

      });
    },
    success: function (title, successfun) {
      if (undefined == title) title = '操作成功';
      var title = title.toString();
      uni.showToast({
        title: title,
        icon: (title.length > 8 ? 'none' : 'success'),
        success: function (res) {
          typeof successfun == 'function' && successfun();
        }
      });
    },
    error: function (title, duration) {
      if (title === false) {
        uni.hideToast();
      } else {
        // if (this.isNull(duration)) duration = 2500;
        if (undefined == title) title = '操作失败';
        uni.showToast({
          title: title.toString(),
          icon: 'none',
          duration: duration
        });
      }
    },
    showLoading: function (title) {
      if (title === false) {
        uni.hideLoading();
      } else {
        if (undefined == title) title = '加载中';
        uni.showLoading({
          title: title.toString(),
          mask: true
        });
      }
    },
    // 点击预览图片
    // previewImage(index, imglist) {
    // 	console.log(index, imglist);
    // 	// 使用uni.previewImage方法预览图片
    // 	uni.previewImage({
    // 		current: index, // 当前显示图片的索引，即点击的图片在数组中的索引
    // 		urls: imglist.map(image => this.globalData.imgUrl + image) // 图片数组，即要预览的图片列表
    // 	});
    // },
    // 拦截未登录触发的页面
    checkLogin() {
      const token = uni.getStorageSync('useinfo'); // 假设登录状态是通过token进行验证的
      console.log(!!token.openid);
      return !!token.openid;
    },
    // getaddres() {
    // 存在bug页面第一次加载互殴抢不到里面的this.globalData.locationInfo
    // 在小程序启动时获取地理位置信息
    // this.$store.dispatch('getLocation')

    // },

    /* async getyuyinbobao() {
      let that = this
      let yuyinflag = await getvehordergetAudioSwitch()
      if (yuyinflag.data.audioEnabled) {
        if (uni.getStorageSync('useinfo').merchantId || uni.getStorageSync('useinfo').staffUserId) {
          setInterval(async function() {
            // 需要重复执行的代码逻辑
            const audioContext = uni.createInnerAudioContext();
            audioContext.src = 'static/mp3/dd.mp3'; // 这里替换为你的音频文件URL
            let data1 = await getbranchlist({
              userLng: '',
              userLat: '',
              name: '',
              uniacid: uni.getStorageSync('useinfo').merchantId || uni.getStorageSync('useinfo').staffUserId
            });
            let obj = {
              startShop: data1.data.rows[0].id,
              id: '',
              status: 2
            }
            let data2 = await getordervehorderlist(obj)
            if (data2.data.total > 0) {
              audioContext.onPlay(() => {
                console.log('开始播放');
              });
              audioContext.onError((res) => {
                console.error('播放失败', res.errMsg);
              });
              audioContext.play();
            }




          }, 30 * 1000);
        }
      }

    } */
  },
  onLaunch: function (opt) {
    this.getwxuserappconfig()

    console.log('request', uploadUrl)

  },
  onShow: function () {
    // this.getaddres()
    console.log('App Show')
    this.globalData.imgUrl = uploadUrl
  },
  onHide: function () {
    console.log('App Hide')
  }
}
</script>

<style lang="scss">
/*每个页面公共css */
@import '@/uni_modules/uni-scss/index.scss';
// 字体图标
@import "./iconfont.css";
/* #ifndef APP-NVUE */
@import '@/static/customicons.css';
// 阿里字体图标
@import "@/static/iconfont.css";

// 设置整个项目的背景色
page {
  background-color: #f5f5f5;
}

view {
  box-sizing: border-box;
  overflow: visible;
}

.flex-y-center {
  display: flex;
  align-items: center;
}

.flex-x-center {
  display: flex;
  justify-content: center;
}

.flex-x-between {
  display: flex;
  justify-content: space-between;
}

.flex-row {
  display: flex;
  flex-direction: row;
}

.flex1 {
  flex-grow: 1;
  flex-shrink: 1;
}

.textellipsis {
  //white-space: nowrap;
  word-wrap: break-word; /* 允许在长单词内部换行 */
  word-break: break-all; /* 允许在任意位置换行 */

}

/* #endif */
.example-info {
  font-size: 14px;
  color: #333;
  padding: 10px;
}

.uni-table-td {

  font-size: 26upx !important;
}

.uni-popup [data-ref="ani"] {
  padding-bottom: 0 !important;
}

.popup-content {
  border-top-left-radius: 15upx;
  border-top-right-radius: 15upx;
  overflow: hidden;
  background-color: #eee;
}

.example-body {

  .uni-date-x,
  .uni-date__x-input {
    font-size: 26upx !important;
  }
}
</style>